﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web.Mvc;

namespace CoolCode.Web.Mvc.UI.Grid.Script
{
    public class GridActionRenderer : IGridActionRenderer
    {
        public void Render(IGridActionModel Model, TextWriter output, ViewContext viewContext)
        {
			return;
            Model.ThrowIfNull();
            output.ThrowIfNull();

            string grid =    viewContext.Controller.ValueProvider.GetValue("grid").AttemptedValue;

            grid.ThrowIfNullOrEmpty("grid");

            //if (!Model.DeleteUrl.EndsWith("/"))
            //{
            //    Model.DeleteUrl += "/";
            //}
            //if (!Model.EditUrl.EndsWith("/"))
            //{
            //    Model.EditUrl += "/";
            //}
            //if (!Model.AddUrl.EndsWith("/"))
            //{
            //    Model.AddUrl += "/";
            //}
            //if (!Model.SubmitUrl.EndsWith("/"))
            //{
            //    Model.SubmitUrl += "/";
            //}

            StringBuilder scriptBuilder = new StringBuilder();
            scriptBuilder.Append("$(\"#" + grid + "\").grid({");
            scriptBuilder.AppendFormat("deleteUrl: \"{0}\",", Model.DeleteUrl);
            scriptBuilder.AppendFormat("editUrl: \"{0}\",", Model.EditUrl);
            scriptBuilder.AppendFormat("addUrl: \"{0}\",", Model.AddUrl);
            scriptBuilder.AppendFormat("submitUrl: \"{0}\"", Model.SubmitUrl);
            scriptBuilder.Append("});");

            output.WriteLine("<script type=\"text/javascript\">");
            output.WriteLine("$(document).ready(function(){");
            output.WriteLine(scriptBuilder);
            output.WriteLine("});");
            output.WriteLine("</script>");
        }
    }
}
